<!DOCTYPE html>
<html lang="en">

<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <meta http-equiv="X-UA-Compatible" content="ie=edge">
    <title>Document</title>
    <style>
        button {
            display: block;
            margin: 20px auto;
            height: 50px;
            width: 80px;
        }
        
        #header {
            width: 700px;
            height: 200px;
            margin: 0 auto;
            display: flex;
        }
        
        .lxx {
            width: 200px;
            height: 200px;
            background-color: red;
            margin-left: 25px;
        }
    </style>
</head>

<body>
    <button>点击一下</button>
    <nav id="header">
        <div class="lxx"></div>
        <div class="lxx"></div>
        <div class="lxx"></div>
    </nav>
    <script>
        var sum =0;
        var btn = document.querySelector('button');
        var lxx = document.getElementsByClassName('lxx');
        btn.onclick = function () {
            sum ++;
            for (var i = 0; i < lxx.length; i++) {
                lxx[i].style.backgroundColor = sum%2==0?'green':'blue';
                }

        }
    </script>
</body>

</html>